Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
How to fix "Uncaught TypeError: db.collection is not a function"?

code in which the error occurs:

const countRef = db.collection('counter').doc('counter');
const increment = firebase.Firestore.FieldValue.increment(1);
const decrement = firebase.Firestore.FieldValue.increment(-1);
function change(num) {
    if (num>0) {
        countRef.update({ counter: increment });
    } else if (num<0) {
        countRef.update({ counter: decrement });
    };
};

The error is in the first line of code. I have also tried to search the internet for answers, but I have not yet found any.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you haven't shown what db is defined to, this answer may be incorrect/not help.


The issue seems to be that you are setting db to an object which doesn't have collection().

Make sure that the db variable is defined and set to the following:

const db = firebase.firestore();

This object has the collection() method defined in it, which may fix the issue.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda